package t

import (
	"net/http"

	"github.com/gin-gonic/gin"
	"go-api-template/api/models/tool"
	"go-api-template/service"
)

func SetRouter(r *gin.RouterGroup) {
	rg := r.Group("/t")
	{
		rg.GET("/:key", func(ctx *gin.Context) {
			if ctx == nil {
				return
			}
			var sl tool.SortLink
			key := ctx.Param("key")
			service.DB.Raw("select * from tool_sort_link where k = ?", key).Scan(&sl)
			ctx.Redirect(http.StatusMovedPermanently, sl.Url)
		})
	}
}
